// // 引入路由组件
// import Home from '@/pages/Home'
// import Login from '@/pages/Login'
// import Register from '@/pages/Register'
// import Search from '@/pages/Search'
// import Detail from '@/pages/Detail'
// import AddCartSuccess from '@/pages/AddCartSuccess'
// import ShopCart from '@/pages/ShopCart'
// import Trade from '@/pages/Trade'
// import Pay from '@/pages/Pay'
// import PaySuccess from '@/pages/PaySuccess'
// import Center from '@/pages/Center'

// // 引入二级路由组件
// import MyOrder from '@/pages/Center/myOrder'
// import GroupOrder from '@/pages/Center/groupOrder' 

// 路由懒加载：当路由被访问时才加载对应组件 这样就更加高效了
// 配置路由
export default [
  {
    path: '/home',
    component: () => import('@/pages/Home'),
    meta: {
      show: true
    }
  },
  {
    path: '/login',
    component: () => import('@/pages/Login'),
    meta: {
      show: false
    }
  },
  {
    path: '/register',
    component: () => import('@/pages/Register'),
    meta: {
      show: false
    }
  },
  {
    // 加? params 参数可传可不传
    path: '/search/:keyword?',
    name: 'search',
    component: () => import('@/pages/Search'),
    meta: {
      show: true
    }
  },
  {
    path: '/detail/:skuid',
    name: 'detail',
    component: () => import('@/pages/Detail'),
    meta: {
      isShow: true
    }
  },
  {
    path: '/addcartsuccess',
    name: 'addcartsuccess',
    component: () => import('@/pages/AddCartSuccess'),
    meta: {
      isShow: true
    }
  },
  {
    path: '/shopcart',
    component: () => import('@/pages/ShopCart'),
    meta: {
      isShow: true
    }
  },
  {
    path: '/trade',
    component: () => import('@/pages/Trade'),
    meta: {
      isShow: true
    },
    // 路由独享守卫
    beforeEnter(to, from, next) {
      // 去交易页面 必须从购物车而来
      if(from.path == '/shopcart') {
        next();
      }else {
        // 其他的路由组件而来 停留在当前
        next(false);
      }
    }
  },
  {
    path: '/pay',
    component: () => import('@/pages/Pay'),
    meta: {
      isShow: true
    },
    beforeEnter(to, from, next) {
      // 去支付页面 必须从交易而来
      if(from.path == '/trade') {
        next();
      }else {
        next(false);
      }
    }
  },
  {
    path: '/paysuccess',
    component: () => import('@/pages/PaySuccess'),
    meta: {
      isShow: true
    }
  },
  {
    path: '/center',
    component: () => import('@/pages/Center'),
    meta: {
      isShow: true
    },
    children: [
      {
        path: 'myorder',
        component: () => import('@/pages/Center/myOrder')
      },
      {
        path: 'grouporder',
        component: () => import('@/pages/Center/groupOrder')
      },
      {
        path: '/center',
        redirect: '/center/myorder'
      }
    ]
  },
  // 重定向 在项目运行时 访问/立马定向到首页
  {
    path: '*',
    redirect: '/home'
  }
]